// 单个用户体会的选项卡
import 'package:flutter/material.dart';

class PersonRealize extends StatefulWidget {
  @override
  _PersonRealizeState createState() => _PersonRealizeState();
}

class _PersonRealizeState extends State<PersonRealize> {
  bool isStart = false;

  @override
  Widget build(BuildContext context) {
    return Card(
      margin: const EdgeInsets.only(left: 4.0,right: 4.0, top: 4.0,bottom: 4.0),
      elevation: 4.0,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          // 一个列, 用户头像, 用户名, 发布的日期
          _buildHeader(context),
          // 显示标题
          _buildTitle(context),
          // 文章的图片
          _buildBody(context),

          _buildFooter(context),
        ],
      ),
    );
  }

  Widget _buildHeader(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Container(
          margin: const EdgeInsets.only(left: 8.0, top: 4.0,right: 4.0,bottom: 0.0),
          child: CircleAvatar(
            radius: 18,
            backgroundImage: NetworkImage(
                "https://avatars1.githubusercontent.com/u/46526052?s=400&u=b0f64fc2f67c45c17341d0090120d1e23f6b6478&v=4"),
          ),
        ),
        Expanded(
          child: Container(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text(
              "在家吃泡面",
              style: TextStyle(
                fontSize: 14.0,
                color: Colors.black,
              ),
            ),
          ),
        ),
        Container(
          padding: const EdgeInsets.only(left: 8.0, right: 8.0),
          child: Text(
            "2小时前",
            //字体的样式
            style: TextStyle(
                fontSize: 14.0,
                fontWeight: FontWeight.normal,
                color: Color(0xff868d9e)),
          ),
        ),
      ],
    );
  }

  Widget _buildTitle(BuildContext context) {
    return Container(
      padding:
          const EdgeInsets.only(left: 16.0, right: 16.0, top: 4.0, bottom: 8.0),
      child: Text(
        "这里是文章的标题: 推荐一本科学巨匠的作品 , 凡尔纳的<<神秘岛>> , 讲述的是 人性 科技 ...",
        maxLines: 2,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.normal),
      ),
    );
  }

  Widget _buildBody(BuildContext context) {
    return Container(
      height: 140.0,
      width: MediaQuery.of(context).size.width,
      child:Container(
        padding: const EdgeInsets.symmetric(horizontal: 4.0),
        child:  Image.network(
          "https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=e85dd07b7f094b36db921ceb9bf71be4/0b55b319ebc4b7459a5999b2c6fc1e178b821540.jpg",
          fit: BoxFit.cover,
        ),
      ),
    );
  }

  _buildFooter(BuildContext context) {
    return Container(
      padding:
          const EdgeInsets.only(left: 8.0, right: 8.0, top: 4.0, bottom: 8.0),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Container(
            child: Text("20人看过"),
          ),
          Container(
            padding: const EdgeInsets.only(left: 8.0),
            child: Text("分类标签"),
          ),
          Expanded(
            child: Container(),
          ),
          GestureDetector(
            onTap: () {
              print("点击的回调函数");
              setState(() {
                isStart = !isStart;
                // todo
              });
            },
            child: isStart
                ? Icon(
                    Icons.star,
                    color: Colors.orange,
                  )
                : Icon(Icons.star),
          )
        ],
      ),
    );
  }
}
